package ihuotui.test.threadpool;

import java.util.concurrent.locks.Lock;

import org.apache.commons.lang3.RandomUtils;

public class LockPrint implements Runnable {
    private Lock lock;
    private int no;
    private int mac;

    public LockPrint(Lock lock, int no, int mac) {
        this.lock = lock;
        this.no = no;
        this.mac = mac;
    }

    @SuppressWarnings("static-access")
    public void run() {
        lock.lock();// 得到锁
        try {
            try {
                Thread.currentThread().sleep(RandomUtils.nextInt(1, 5) * 100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            if (mac==2) {
                System.out.println("mac:"+mac+" no:"+no);
//            }
        } finally {
            lock.unlock();// 释放锁
        }
    }
}
